//
//  ViewController.m
//  CustomizeCellXib
//
//  Created by xiewei on 16/6/18.
//  Copyright © 2016年 xiewei. All rights reserved.
//

#import "ViewController.h"
#import "XWCell.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

@interface ViewController () <UITableViewDataSource,UITableViewDelegate>
/// tableview
@property (nonatomic,strong) UITableView *tableview;
/// 数据源
@property (nonatomic,strong) NSMutableArray *mArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    
    /// 设置cell高度
    self.tableview.rowHeight = 100;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.mArr count];
}
- (XWCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XWCell *cell = [XWCell xwcellWithTableView:tableView];
    cell.dict = self.mArr[indexPath.row];
    
    return cell;
}

#pragma mark - 懒加载
- (NSMutableArray *)mArr {
    if (_mArr == nil) {
        _mArr = [[NSMutableArray alloc] init];
        
        for (int i = 0; i < 20; i++) {
            NSDictionary *dict = @{@"img":@"22.jpg",@"index":[NSString stringWithFormat:@"第%d张图片",i + 1]};
            [_mArr addObject:dict];
        }
    }
    return _mArr;
}
- (UITableView *)tableview {
    if (_tableview == nil) {
        _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 20)];
        [self.view addSubview:_tableview];
    }
    return _tableview;
}

@end
